home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / casm / au116-as.exe / IBMDOS / PRINTF.CPP < prev   
C/C++ Source or Header  |  1994-02-06  |  3KB  |  152 lines

  1. #include "..\au.hpp"
  2.  
  3. /***************************************************************************/
  4. static void display_setcolor(AU *au, char color)
  5. {
  6.     if (color >= '0' && color <= '7')
  7.         au->current_color = color - 48 + 8;
  8.     else
  9.         au->current_color = color - 'A';
  10.  
  11.     return;
  12. }
  13. /***************************************************************************/
  14. static void display_onechar(AU *au, char c)
  15. {
  16. //      BYTE savecolor;
  17.  
  18.     if (c != '\n' && c != '\r' && c != '\a')
  19.     {
  20.         _BL = au->current_color;
  21.         _AL = ' ';
  22.         _AH = 0x09;
  23.         _BH = 0;
  24.         _CX = 1;
  25.         __int__(0x10);
  26.     }
  27. #if 0
  28.     else if (c == '\n')   /* Print spaces to the end to clean up color stuff */
  29.     {
  30.         savecolor = au->current_color;
  31.         au->current_color = 0;
  32.         for (;;)
  33.         {
  34.             _BH = 0;
  35.             _AH = 0x03;
  36.             __int__(0x10);
  37.             if (_DL == 0)
  38.                 break;
  39.  
  40.             display_onechar(au, ' ');
  41.         }
  42.         au->current_color = savecolor;
  43.         return;
  44.     }
  45. #endif
  46.  
  47.     _BL = au->current_color;
  48.     _AL = c;
  49.     _AH = 0x0e;
  50.     _BH = 0;
  51.     _CX = 1;
  52.     __int__(0x10);
  53.  
  54. #if 0
  55.     /* not sure why this is necessary, but without it the attribute seems
  56.        to bleed into the next line */
  57.     if (c != '\n' && c != '\r' && c != '\a')
  58.     {
  59.         _BL = 7;
  60.         _AL = ' ';
  61.         _AH = 0x09;
  62.         _BH = 0;
  63.         _CX = 264;
  64.         __int__(0x10);
  65.     }
  66. #endif
  67. }
  68. /***************************************************************************/
  69. static void display_string(AU *au, char *string)
  70. {
  71.     while (*string != '\0')
  72.     {
  73.         if (*string == '@' && *(string+1) == '?')
  74.         {
  75.             display_setcolor(au, *(string+2));
  76.             string+=3;
  77.         }
  78.         else
  79.         {
  80.             if (au->colorized)
  81.             {
  82.                 if (*string == '\n')
  83.                     display_onechar(au, '\r');
  84.                 display_onechar(au, *string);
  85.             }
  86.             else
  87.                 putchar(*string);
  88.  
  89.             if (*string == '\n')                 /* Check for control S */
  90.             {
  91.                 if (is_next_control_s())
  92.                 {
  93.                     my_getch();    /* Get control S */
  94.                     my_getch();    /* Wait for yet another character */
  95.                 }
  96.             }
  97.             string++;
  98.         }
  99.     }
  100. }
  101. /***************************************************************************/
  102. static void au_printfv(AU *au, char *format, va_list plist)
  103. {
  104.     char string[2000];
  105.  
  106.     vsprintf(string, format, plist);
  107.     display_string(au, string);
  108. }
  109. /***************************************************************************/
  110. void au_printf(AU *au, char *format, ...)
  111. {
  112.     va_list plist;
  113.  
  114.     va_start(plist, format);
  115.     au_printfv(au, format, plist);
  116.     va_end(plist);
  117.  
  118.     return;
  119. }
  120. /***************************************************************************/
  121. static void au_printf_cv(AU *au, char color, char *format, va_list plist)
  122. {
  123.     BYTE color_hold;
  124.  
  125.     color_hold = au->current_color;
  126.     au->current_color = color;
  127.     au_printfv(au, format, plist);
  128.     au->current_color = color_hold;
  129. }
  130. /***************************************************************************/
  131. void au_printf_c(AU *au, char color, char *format, ...)
  132. {
  133.     va_list plist;
  134.  
  135.     va_start(plist, format);
  136.     au_printf_cv(au, color, format, plist);
  137.     return;
  138. }
  139. /***************************************************************************/
  140. void au_printf_error(AU *au, char *format, ...)
  141. {
  142.     va_list plist;
  143.  
  144.     au_printf(au, "\a");
  145.  
  146.     va_start(plist, format);
  147.     au_printf_cv(au, 12, format, plist);
  148.     au_printf(au, "\n");
  149.     va_end(plist);
  150.     return;
  151. }
  152.